package com.zdsoft.blp.zongbuju.shouye.linliquan.activity;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.zdsoft.blp.R;
import com.zdsoft.blp.gongyong.API.API;
import com.zdsoft.blp.gongyong.linliFragment.LinLiView;
import com.zdsoft.blp.gongyong.net.BaseActivity;
import com.zdsoft.blp.gongyong.net.Net;
import com.zdsoft.blp.gongyong.net.NetCallback;
import com.zdsoft.blp.zongbuju.shouye.linliquan.adapter.PCfragmentAdapter;
import com.zdsoft.blp.zongbuju.shouye.linliquan.fragment.ESfragmentLeft;
import com.zdsoft.blp.zongbuju.shouye.linliquan.fragment.ESfragmentRight;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/8/31.
 */
public class LLShiChangActivitv extends BaseActivity implements View.OnClickListener,NetCallback{
    private ImageView title_fenlei;
    private LinLiView llv;          //封装的viewPager+fragment
    private TextView tv_title;      //封装的标题
    private ImageView title_bianji;//编辑图片
    private static  final  int CODE=1;
    public int source;
    @Override
    protected void init() {
        setContentView(R.layout.linli_pinchexinxi);
        llv = find(R.id.llv);
        //设置分类图片显示
        title_fenlei = find(R.id.title_fenlei);
        title_fenlei.setVisibility(View.VISIBLE);
        title_fenlei.setOnClickListener(this);
        //图片跳转到编辑页面
        title_bianji = find(R.id.title_bianji);
        title_bianji.setOnClickListener(this);
        //设置标题
        tv_title = find(R.id.tv_title);
        tv_title.setText("二手市场");
        llv.getTv_left().setText("转让");
        llv.getTv_right().setText("求购");
        Intent intent=getIntent();
        source=intent.getIntExtra("source",1);
        //加载fragment布局
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(new ESfragmentLeft());

        fragments.add(new ESfragmentRight());
        llv.getVp().setAdapter(new PCfragmentAdapter(getSupportFragmentManager(),fragments));

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.title_fenlei:
                Intent intent = new Intent(LLShiChangActivitv.this,LLShiChangDialog.class);
                startActivityForResult(intent,CODE);
                break;
            case R.id.title_bianji:
                Intent intent1 = new Intent(LLShiChangActivitv.this,FBESActivity.class);
                if(llv.isChack()){
                    intent1.putExtra("title","转让");

                }else{
                    intent1.putExtra("title","求购");

                }
                startActivity(intent1);
                break;
        }
    }
    //重写result方法接收dialog返回的类别值
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
                switch (requestCode){
                    case CODE:
                        if(resultCode==RESULT_OK){
                            String leibie =  data.getStringExtra("leibie");
                            getNet(leibie);
                            Toast.makeText(this,leibie,Toast.LENGTH_SHORT).show();
                        }
                        break;
                }
    }

    private void getNet(String leibie) {
        Net net=new Net();
        net.url= API.ESINFO_URL;
        net.nameSpace=API.ESINFO_NAMESPACE;
        net.methodName=API.COLUMNLIST;//columnList
        getServer(net,this);
    }


    @Override
    public void onResponse(boolean flag, int code, String res) {

    }
}
